package jnpf.engine.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import jnpf.base.ActionResult;
import jnpf.constant.PermissionConst;
import jnpf.engine.custom.constants.GlobalProcessVariableConstants;
import jnpf.engine.entity.FlowTaskOperatorRecordEntity;
import jnpf.engine.entity.FlowTemplateEntity;
import jnpf.engine.enums.FieldTypeEnums;
import jnpf.engine.enums.FieldValueTypeEnums;
import jnpf.engine.model.FlowTaskOperatorRecordDTO;
import jnpf.engine.model.flowengine.FlowModel;
import jnpf.engine.model.flowengine.shuntjson.childnode.FuncConfig;
import jnpf.engine.model.flowengine.shuntjson.childnode.GroupsModel;
import jnpf.engine.model.flowengine.shuntjson.childnode.ParamConfig;
import jnpf.engine.model.flowengine.shuntjson.childnode.Properties;
import jnpf.engine.service.FlowTaskOperatorRecordService;
import jnpf.engine.service.FlowTemplateService;
import jnpf.permission.entity.OrganizeEntity;
import jnpf.permission.entity.UserEntity;
import jnpf.permission.entity.UserRelationEntity;
import jnpf.permission.service.OrganizeService;
import jnpf.permission.service.UserRelationService;
import jnpf.permission.service.UserService;
import jnpf.util.JsonUtil;
import jnpf.util.StringUtil;
import jnpf.util.visiual.JnpfKeyConsts;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.*;

import static jnpf.engine.custom.constants.BasicActivitiConstants.taskDescriptionSeparatorNoLogic;
import static jnpf.engine.custom.constants.RootExecutionVariableConstants.*;
import static jnpf.engine.util.BpmnModelUtils.getFirstNode;
import static jnpf.engine.util.BpmnModelUtils.getFirstNodeProperty;
import static jnpf.engine.util.EvalUtils.formula;

/**
 * @author Doctor4JavaEE
 * @since 2024/3/19
 */
@Component
@SuppressWarnings("all")
public class TryEvaluateUtils {
    public static String START_USER="startUser";
    public static String START_TIME="startTime";
    public static String CURRENT_TIME="currentTime";
    public static String PROCESS_NAME="processName";
    public static String PROCESS_CODE="processCode";



    public static String COMMENT="comment";
    public static String AUDIT_NUM="auditNum";

    public static String REJECT_NUM="rejectNum";
    public static String ABSTENTION_NUM="abstentionNum";
    public static String NODE_ASSIGNEE="nodeAssignee";
    public static String NODE_RESULT="result";
    public static String NODE_EXCEPTION="exception";
    public static String TIME_FORMAT="yyyy-MM-dd HH:mm:ss";





    public Boolean devMode(DelegateExecution execution,String nodeId){
        String processDefinitionId = execution.getProcessDefinitionId();
        Process bpmnModelMainProcess = BpmnModelUtils.getBpmnModelMainProcess(processDefinitionId);
        String attributeValueByTaskDefinitionKey = BpmnModelUtils.getAttributeValueByTaskDefinitionKey(bpmnModelMainProcess, nodeId, "");
        Properties properties = JSONObject.parseObject(attributeValueByTaskDefinitionKey, new TypeReference<Properties>() {
        });
        FuncConfig conditionFuncConfig = properties.getConditionFuncConfig();
        FlowTaskOperatorRecordService flowTaskOperatorRecordService = SpringContextHolder.getBean(FlowTaskOperatorRecordService.class);
        LambdaQueryWrapper<FlowTaskOperatorRecordEntity> flowTaskOperatorRecordEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        flowTaskOperatorRecordEntityLambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getTaskId,execution.getProcessInstanceId());
        UserTask firstNode = getFirstNode(bpmnModelMainProcess);
        flowTaskOperatorRecordEntityLambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getNodeCode,firstNode.getId());
        FlowTaskOperatorRecordEntity flowTaskOperatorRecordEntity = flowTaskOperatorRecordService.list(flowTaskOperatorRecordEntityLambdaQueryWrapper).get(0);
        FlowModel flowModel = new FlowModel();
        Properties applyProperties = getFirstNodeProperty(execution.getProcessDefinitionId());
        Map<String, Map<String, Object>> nodeFormData = FlowContextHolder.getNodeFormData();
        Map<String,Object> dataMap = new HashMap<>();
        Set<String> strings = nodeFormData.keySet();
        for (String string : strings) {
            Map<String, Object> tempMap = nodeFormData.get(string);
            dataMap.putAll(tempMap);
        }
        flowModel.setFormData(dataMap);
        FlowTaskOperatorRecordDTO flowTaskOperatorRecordDTO = new FlowTaskOperatorRecordDTO();
        flowTaskOperatorRecordDTO.setAssignee(flowTaskOperatorRecordEntity.getHandleId());
        flowTaskOperatorRecordDTO.setProcessInstanceId(flowTaskOperatorRecordEntity.getTaskId());
        flowTaskOperatorRecordDTO.setTaskId(flowTaskOperatorRecordEntity.getTaskNodeId());
        conditionFuncConfig.setOn(Boolean.TRUE);
        FlowMsgUtil flowMsgUtil = SpringContextHolder.getBean(FlowMsgUtil.class);
        ActionResult event = flowMsgUtil.event(12, properties, flowTaskOperatorRecordDTO, flowModel,bpmnModelMainProcess,nodeId);
        Integer code = event.getCode();
        if(code == 200){
            Object data = event.getData();
            if(data instanceof Boolean){
                return (Boolean) data;
            }
            else{
                return Boolean.FALSE;
            }
        }
        return Boolean.FALSE;
    }


    public  Object evaluateFiledNameValue(DelegateExecution execution,String jnpfKey,Integer jnpfKeyType,String filedName){
        Map<String, Object> transientVariables = execution.getTransientVariables();
        if(FieldTypeEnums.FROM_FORM.getCode().equals(jnpfKeyType)){
            return transientVariables.get(filedName);
        }
        else if(FieldTypeEnums.FROM_FORMULA.getCode().equals(jnpfKeyType)){
            GroupsModel groupsModel  = new GroupsModel();
            groupsModel.setFieldName(filedName);
            return formula(groupsModel,transientVariables);
        }
        else if(FieldTypeEnums.FORM_BASE.getCode().equals(jnpfKeyType)){
            Map<String, Object> transientVariables1 = execution.getTransientVariables();
            Map<String, Object> variables = execution.getVariables();
            transientVariables1.putAll(variables);
            if(START_USER.equals(filedName)){

                return MapUtil.getStr(transientVariables1, GlobalProcessVariableConstants.APPLY_USER_ID)+"--user";
            }
            else if(START_TIME.equals(filedName)){
                return transientVariables1.get(GlobalProcessVariableConstants.CURRENT_CREATE_TIME);
            }
            else if(CURRENT_TIME.equals(filedName)){
                return new Date();
            }
            else if(PROCESS_NAME.equals(filedName)){
                return transientVariables1.get(GlobalProcessVariableConstants.BUSINESS_TITLE);
            }
            else if(PROCESS_CODE.equals(filedName)){
                String str = MapUtil.getStr(transientVariables1, GlobalProcessVariableConstants.FLOW_ENGINE_ID);
                FlowTemplateService flowTemplateService = SpringContextHolder.getBean(FlowTemplateService.class);
                LambdaQueryWrapper<FlowTemplateEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(FlowTemplateEntity::getId,str);
                lambdaQueryWrapper.select(FlowTemplateEntity::getId,FlowTemplateEntity::getEnCode);
                FlowTemplateEntity flowTemplateEntity = flowTemplateService.getOne(lambdaQueryWrapper);
                return flowTemplateEntity.getEnCode();
            }
            else{
                return "";
            }
        }
        else if(FieldTypeEnums.FROM_APPROVER_NODE.getCode().equals(jnpfKeyType)){
            String[] split = filedName.split(taskDescriptionSeparatorNoLogic);
            String nodeId=split[0];
            String action=split[1];
            if(COMMENT.equals(action)){
                FlowTaskOperatorRecordService flowTaskOperatorRecordService = SpringContextHolder.getBean(FlowTaskOperatorRecordService.class);
                LambdaQueryWrapper<FlowTaskOperatorRecordEntity>  lambdaQueryWrapper =  new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getNodeCode,nodeId);
                lambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getTaskId,execution.getProcessInstanceId());
                lambdaQueryWrapper.select(FlowTaskOperatorRecordEntity::getId,FlowTaskOperatorRecordEntity::getHandleOpinion);
                List<FlowTaskOperatorRecordEntity> list = flowTaskOperatorRecordService.list(lambdaQueryWrapper);
                List<String> comments= new ArrayList<>();
                for (FlowTaskOperatorRecordEntity flowTaskOperatorRecordEntity : list) {
                    comments.add(flowTaskOperatorRecordEntity.getHandleOpinion());
                }
                return   CollUtil.join(comments, ",");
            }
            else if(AUDIT_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_AUDIT);
            }
            else if(REJECT_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_REJECT);
            }
            else if(ABSTENTION_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_ABSTENTION);
            }
            else if(NODE_ASSIGNEE.equals(action)){
                return transientVariables.get(nodeId+"assigneeList");
            }
            else {
                return "";
            }
        }
        else if(FieldTypeEnums.FROM_OTHER_NODE.getCode().equals(jnpfKeyType)){
            String[] split = filedName.split(taskDescriptionSeparatorNoLogic);
            String nodeId=split[0];
            String action=split[1];
            if(NODE_RESULT.equals(action)){
                return   transientVariables.get(nodeId + NODE_RESULT);
            }
            else if(NODE_EXCEPTION.equals(action)){
                return   transientVariables.get(nodeId + NODE_EXCEPTION);
            }
            else{
                return "";
            }
        }
        else if(FieldTypeEnums.FROM_PARAM.getCode().equals(jnpfKeyType)){
           //
            Properties firstNodeProperty = BpmnModelUtils.getFirstNodeProperty(execution.getProcessDefinitionId());
            List<ParamConfig> paramsConfig = firstNodeProperty.getParamsConfig();
            Object paramValue=null;
            for (ParamConfig paramConfig : paramsConfig) {
                 if(filedName.equals(paramConfig.getField())){
                     paramValue=paramConfig.getFieldValue();
                     break;
                 }
            }
            return paramValue;
        }
        else {
            return "";
        }
    }

    public  Object evaluateFiledValue(DelegateExecution execution,String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        String decodeStr = Base64.decodeStr(jnpfValue.toString());
        Object parse = JSONObject.parse(decodeStr);
        Map<String, Object> transientVariables = execution.getTransientVariables();
        if(FieldValueTypeEnums.FROM_FORM.getCode().equals(jnpfValueType)){
            return transientVariables.get(parse.toString());
        }
        else if(FieldValueTypeEnums.FORM_CUSTOM.getCode().equals(jnpfValueType)){
            return parse;
        }
        else if(FieldValueTypeEnums.FORM_BASE.getCode().equals(jnpfValueType)){
            String jnpfValueStr = parse.toString();
            Map<String, Object> variables = execution.getVariables();
            if(START_USER.equals(jnpfValueStr)){
                return MapUtil.getStr(variables, GlobalProcessVariableConstants.APPLY_USER_ID);
            }
            else if(START_TIME.equals(jnpfValueStr)){
                return variables.get(GlobalProcessVariableConstants.CURRENT_CREATE_TIME);
            }
            else if(CURRENT_TIME.equals(jnpfValueStr)){
                return new Date();
            }
            else if(PROCESS_NAME.equals(jnpfValueStr)){
                return variables.get(GlobalProcessVariableConstants.BUSINESS_TITLE);
            }
            else if(PROCESS_CODE.equals(jnpfValueStr)){
                String str = MapUtil.getStr(variables, GlobalProcessVariableConstants.FLOW_ENGINE_ID);
                FlowTemplateService flowTemplateService = SpringContextHolder.getBean(FlowTemplateService.class);
                LambdaQueryWrapper<FlowTemplateEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(FlowTemplateEntity::getId,str);
                lambdaQueryWrapper.select(FlowTemplateEntity::getId,FlowTemplateEntity::getEnCode);
                FlowTemplateEntity flowTemplateEntity = flowTemplateService.getOne(lambdaQueryWrapper);
                return flowTemplateEntity.getEnCode();
            }
            else{
                return "";
            }
        }
        else if(FieldValueTypeEnums.FROM_APPROVER_NODE.getCode().equals(jnpfValueType)){
            String jnpfValueStr = parse.toString();
            String[] split = jnpfValueStr.split(taskDescriptionSeparatorNoLogic);
            String nodeId=split[0];
            String action=split[1];
            if(COMMENT.equals(action)){
                FlowTaskOperatorRecordService flowTaskOperatorRecordService = SpringContextHolder.getBean(FlowTaskOperatorRecordService.class);
                LambdaQueryWrapper<FlowTaskOperatorRecordEntity>  lambdaQueryWrapper =  new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getNodeCode,nodeId);
                lambdaQueryWrapper.eq(FlowTaskOperatorRecordEntity::getTaskId,execution.getProcessInstanceId());
                lambdaQueryWrapper.select(FlowTaskOperatorRecordEntity::getId,FlowTaskOperatorRecordEntity::getHandleOpinion);
                List<FlowTaskOperatorRecordEntity> list = flowTaskOperatorRecordService.list(lambdaQueryWrapper);
                List<String> comments= new ArrayList<>();
                for (FlowTaskOperatorRecordEntity flowTaskOperatorRecordEntity : list) {
                    comments.add(flowTaskOperatorRecordEntity.getHandleOpinion());
                }
                return   CollUtil.join(comments, ",");
            }
            else if(AUDIT_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_AUDIT);
            }
            else if(REJECT_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_REJECT);
            }
            else if(ABSTENTION_NUM.equals(action)){
                return transientVariables.get(MULTI_INSTANCE_NUM_ABSTENTION);
            }
            else if(NODE_ASSIGNEE.equals(action)){
                return transientVariables.get(nodeId+"assigneeList");
            }
            else {
                return "";
            }
        }
        else if(FieldValueTypeEnums.FROM_OTHER_NODE.getCode().equals(jnpfValueType)){
            String jnpfValueStr = parse.toString();
            String[] split = jnpfValueStr.split(taskDescriptionSeparatorNoLogic);
            String nodeId=split[0];
            String action=split[1];
            if(NODE_RESULT.equals(action)){
                return   transientVariables.get(nodeId + NODE_RESULT);
            }
            else if(NODE_EXCEPTION.equals(action)){
                return   transientVariables.get(nodeId + NODE_EXCEPTION);
            }
            else{
                return "";
            }
        }
        else if(FieldTypeEnums.FROM_PARAM.getCode().equals(jnpfValueType)){
            //
            String jnpfValueStr = parse.toString();
            Properties firstNodeProperty = BpmnModelUtils.getFirstNodeProperty(execution.getProcessDefinitionId());
            List<ParamConfig> paramsConfig = firstNodeProperty.getParamsConfig();
            Object paramValue=null;
            for (ParamConfig paramConfig : paramsConfig) {
                if(jnpfValueStr.equals(paramConfig.getField())){
                    paramValue=paramConfig.getFieldValue();
                    break;
                }
            }
            return paramValue;
        }
        else {
            return "";
        }
    }


    public Boolean equals(DelegateExecution execution,
                          String jnpfKey,Integer jnpfKeyType,String filedName,
                          String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        return ObjectUtil.equals(o,o1);
    }

    public Boolean notEquals(DelegateExecution execution,
                          String jnpfKey,Integer jnpfKeyType,String filedName,
                          String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        return !equals(execution,jnpfKey,jnpfKeyType,filedName,jnpfValueKey,jnpfValueType,jnpfValue);
    }


    public Boolean containsEx(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        if(JnpfKeyConsts.COM_INPUT.equals(jnpfKey) ||JnpfKeyConsts.TEXTAREA.equals(jnpfKey)){
            if(!(o1 instanceof String)){
                return Boolean.FALSE;
            }
            else{
                String oStr=(String)o;
                int i = oStr.indexOf(o1.toString());
                if(i!=-1){
                    return Boolean.TRUE;
                }
                return Boolean.FALSE;
            }
        }
        else{
            List<String> list = new ArrayList<>();
            try {
                list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
            } catch (Exception e) {

            }
            if (o instanceof List) {
                list.addAll((List) o);
            } else {
                list.addAll(Arrays.asList(String.valueOf(o).split(",")));
            }
            if(o1 instanceof Collection){
                return CollectionUtil.intersection(list,(Collection)o1).size()>0;
            }
            else{
                return CollUtil.contains(list,o1);
            }
        }

    }

    public Boolean notContainsEx(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.TRUE;
        }
        if(JnpfKeyConsts.COM_INPUT.equals(jnpfKey) ||JnpfKeyConsts.TEXTAREA.equals(jnpfKey)){
            if(!(o1 instanceof String)){
                return Boolean.TRUE;
            }
            else{
                String oStr=(String)o;
                int i = oStr.indexOf(o1.toString());
                if(i!=-1){
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            }
        }
        else{
            List<String> list = new ArrayList<>();
            try {
                list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
            } catch (Exception e) {

            }
            if (o instanceof List) {
                list.addAll((List) o);
            } else {
                list.addAll(Arrays.asList(String.valueOf(o).split(",")));
            }
            return !CollUtil.contains(list,o1);
        }

    }


    public Boolean isBlank(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        if(ObjectUtil.isEmpty(o) ){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    public Boolean isNotBlank(DelegateExecution execution,
                           String jnpfKey,Integer jnpfKeyType,String filedName
                           ){
        return !isBlank(execution,jnpfKey,jnpfKeyType,filedName);
    }


    public Boolean isStartWith(DelegateExecution execution,
                          String jnpfKey,Integer jnpfKeyType,String filedName,
                          String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        return o.toString().startsWith(o1.toString());
    }
    public Boolean isStartNotWith(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.TRUE;
        }
        return !(o.toString().startsWith(o1.toString()));
    }
    public Boolean isEndWith(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        return o.toString().endsWith(o1.toString());
    }
    public Boolean isEndNotWith(DelegateExecution execution,
                                  String jnpfKey,Integer jnpfKeyType,String filedName,
                                  String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.TRUE;
        }
        return !(o.toString().endsWith(o1.toString()));
    }

    public Boolean daYu(DelegateExecution execution,
                      String jnpfKey,Integer jnpfKeyType,String filedName,
                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        return v>v1;
    }
    public Boolean xiaoYu(DelegateExecution execution,
                      String jnpfKey,Integer jnpfKeyType,String filedName,
                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        return v<v1;
    }
    public Boolean daDengYu(DelegateExecution execution,
                      String jnpfKey,Integer jnpfKeyType,String filedName,
                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){

        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        return v>=v1;
    }
    public Boolean xiaoDengYu(DelegateExecution execution,
                      String jnpfKey,Integer jnpfKeyType,String filedName,
                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        return v<=v1;
    }

    public Boolean isNumberValueScope(DelegateExecution execution,
                      String jnpfKey,Integer jnpfKeyType,String filedName,
                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,
                          String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        Object o2 = evaluateFiledValue(execution, jnpfValueKey1, jnpfValueType1, jnpfValue1);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1) || ObjectUtil.isEmpty(o2)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        double v2 = toDouble(o2);
        return v1<v && v<v2 ;
    }
    public Boolean isNumberValueScope1(DelegateExecution execution,
                                      String jnpfKey,Integer jnpfKeyType,String filedName,
                                      String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,
                                      String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        Object o2 = evaluateFiledValue(execution, jnpfValueKey1, jnpfValueType1, jnpfValue1);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1) || ObjectUtil.isEmpty(o2)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        double v2 = toDouble(o2);
        return v1>v && v>v2 ;
    }

    public Boolean isNumberValueScope2(DelegateExecution execution,
                                       String jnpfKey,Integer jnpfKeyType,String filedName,
                                       String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,
                                       String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        Object o2 = evaluateFiledValue(execution, jnpfValueKey1, jnpfValueType1, jnpfValue1);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1) || ObjectUtil.isEmpty(o2)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        double v2 = toDouble(o2);
        return v1<=v && v<=v2 ;
    }

    public Boolean isNumberValueScope3(DelegateExecution execution,
                                       String jnpfKey,Integer jnpfKeyType,String filedName,
                                       String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,
                                       String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1){
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        Object o2 = evaluateFiledValue(execution, jnpfValueKey1, jnpfValueType1, jnpfValue1);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1) || ObjectUtil.isEmpty(o2)){
            return Boolean.FALSE;
        }
        double v = toDouble(o);
        double v1 = toDouble(o1);
        double v2 = toDouble(o2);
        return v1>=v && v>=v2 ;
    }




    public Boolean isBefore(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat){
        Date keyDate= null;
        Date valueDate = null;
        keyDate = getKeyDate(execution, jnpfKey, jnpfKeyType, filedName, nameFormat, keyDate);
        valueDate = getValueDate(execution, jnpfValueKey, jnpfValueType, jnpfValue, valueFormat, valueDate);
        if(keyDate==null || valueDate==null){
            return Boolean.FALSE;
        }
        return keyDate.before(valueDate);
    }

    public Boolean isBelong(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){

        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        //判空
        if(jnpfKey.equals(jnpfValueKey)){
            //
            if(JnpfKeyConsts.COMSELECT.equals(jnpfKey) || JnpfKeyConsts.DEPSELECT.equals(jnpfKey) || JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey) || JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)){
                //
                if(o1 instanceof Collection){
                    //
                    Set<String> set= new HashSet<>();

                    List<String> list = new ArrayList<>();
                    List o1List= (List) o1;
                    Object o3 = o1List.get(0);
                    // 单部门,但是多级
                    if(o3 instanceof  String){
                        list.add((String) o1List.get(o1List.size()-1));
                    }
                    //多部门的情况
                    else if(o3 instanceof List){
                        List<List<String>> orgList= (List<List<String>>) o1List ;
                        for (int i = 0; i < orgList.size(); i++) {
                            List<String> list1 = orgList.get(i);
                            list.add(list1.get(list1.size()-1));
                        }
                    }

                    //到此为止, 拿到了o1 的所有的 机构id
                    for (String id : list) {
                        set.add(id);//添加本身
                        List<String> underOrganizations = organizeService.getUnderOrganizations(id, true);
                        set.addAll(underOrganizations);
                    }


                    //判断o 是 Collection 还是 字符串
                    if(o instanceof Collection){
                        Set<String> finalSet= new HashSet<>();
                        //
                        List oList= (List) o;
                        Object o4 = oList.get(0);
                        // 单部门,但是多级
                        if(o4 instanceof  String){
                            finalSet.add((String) oList.get(oList.size()-1));
                        }
                        //多部门的情况
                        else if(o4 instanceof List){
                            List<List<String>> orgList= (List<List<String>>) oList ;
                            for (int i = 0; i < orgList.size(); i++) {
                                List<String> list1 = orgList.get(i);
                                finalSet.add(list1.get(list1.size()-1));
                            }
                        }
                        //
                        return set.containsAll(finalSet);

                    }
                    else{
                        return CollUtil.contains(set,o);
                    }
                }
                else{
                    //按现在理论是进不来的
                    return Boolean.TRUE;
//                    //
//                    //判断o 是 Collection 还是 字符串
//                    if(o instanceof Collection){
//                        List<String> list = new ArrayList<>();
//                        try {
//                            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
//                        } catch (Exception e) {
//
//                        }
//                        list.addAll((List) o);
//                        return CollUtil.contains(list,o1);
//                    }
//                    else{
//                        return ObjectUtil.equals(o,o1);
//                    }
                }
            }
            else{
                return Boolean.FALSE;
            }
        }
        else{
            return Boolean.FALSE;
        }




    }

    public Boolean isNotBelong(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){


        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.TRUE;
        }
        //判空
        if(jnpfKey.equals(jnpfValueKey)){
            //
            if(JnpfKeyConsts.COMSELECT.equals(jnpfKey) || JnpfKeyConsts.DEPSELECT.equals(jnpfKey) || JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey) || JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)){
                //
                if(o1 instanceof Collection){
                    //
                    Set<String> set= new HashSet<>();

                    List<String> list = new ArrayList<>();
                    List o1List= (List) o1;
                    Object o3 = o1List.get(0);
                    // 单部门,但是多级
                    if(o3 instanceof  String){
                        list.add((String) o1List.get(o1List.size()-1));
                    }
                    //多部门的情况
                    else if(o3 instanceof List){
                        List<List<String>> orgList= (List<List<String>>) o1List ;
                        for (int i = 0; i < orgList.size(); i++) {
                            List<String> list1 = orgList.get(i);
                            list.add(list1.get(list1.size()-1));
                        }
                    }

                    //到此为止, 拿到了o1 的所有的 机构id
                    for (String id : list) {
                        set.add(id);//添加本身
                        List<String> underOrganizations = organizeService.getUnderOrganizations(id, true);
                        set.addAll(underOrganizations);
                    }


                    //判断o 是 Collection 还是 字符串
                    if(o instanceof Collection){
                        Set<String> finalSet= new HashSet<>();
                        //
                        List oList= (List) o;
                        Object o4 = oList.get(0);
                        // 单部门,但是多级
                        if(o4 instanceof  String){
                            finalSet.add((String) oList.get(oList.size()-1));
                        }
                        //多部门的情况
                        else if(o4 instanceof List){
                            List<List<String>> orgList= (List<List<String>>) oList ;
                            for (int i = 0; i < orgList.size(); i++) {
                                List<String> list1 = orgList.get(i);
                                finalSet.add(list1.get(list1.size()-1));
                            }
                        }
                        //
                        return !set.containsAll(finalSet);

                    }
                    else{
                        return !CollUtil.contains(set,o);
                    }
                }
                else{
                    //按现在理论是进不来的
                    return Boolean.TRUE;
//                    //
//                    //判断o 是 Collection 还是 字符串
//                    if(o instanceof Collection){
//                        List<String> list = new ArrayList<>();
//                        try {
//                            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
//                        } catch (Exception e) {
//
//                        }
//                        list.addAll((List) o);
//                        return !CollUtil.contains(list,o1);
//                    }
//                    else{
//                        return !ObjectUtil.equals(o,o1);
//                    }
                }
            }
            else{
                return Boolean.FALSE;
            }
        }
        else{
            return Boolean.FALSE;
        }
    }

    public Boolean isSubBelong(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){


        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        //判空
        if(jnpfKey.equals(jnpfValueKey)){
            //
            if(JnpfKeyConsts.COMSELECT.equals(jnpfKey) || JnpfKeyConsts.DEPSELECT.equals(jnpfKey) || JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey) || JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)){
                //
                if(o instanceof Collection){
                    //
                    Set<String> set= new HashSet<>();

                    List<String> list = new ArrayList<>();
                    List o1List= (List) o;
                    Object o3 = o1List.get(0);
                    // 单部门,但是多级
                    if(o3 instanceof  String){
                        list.add((String) o1List.get(o1List.size()-1));
                    }
                    //多部门的情况
                    else if(o3 instanceof List){
                        List<List<String>> orgList= (List<List<String>>) o1List ;
                        for (int i = 0; i < orgList.size(); i++) {
                            List<String> list1 = orgList.get(i);
                            list.add(list1.get(list1.size()-1));
                        }
                    }

                    //到此为止, 拿到了o1 的所有的 机构id
                    for (String id : list) {
                        set.add(id);//添加本身
                        List<String> underOrganizations = organizeService.getUnderOrganizations(id, true);
                        set.addAll(underOrganizations);
                    }


                    //判断o 是 Collection 还是 字符串
                    if(o1 instanceof Collection){
                        Set<String> finalSet= new HashSet<>();
                        //
                        List oList= (List) o1;
                        Object o4 = oList.get(0);
                        // 单部门,但是多级
                        if(o4 instanceof  String){
                            finalSet.add((String) oList.get(oList.size()-1));
                        }
                        //多部门的情况
                        else if(o4 instanceof List){
                            List<List<String>> orgList= (List<List<String>>) oList ;
                            for (int i = 0; i < orgList.size(); i++) {
                                List<String> list1 = orgList.get(i);
                                finalSet.add(list1.get(list1.size()-1));
                            }
                        }
                        //
                        return set.containsAll(finalSet);

                    }
                    else{
                        return CollUtil.contains(set,o1);
                    }
                }
                else{
                    //按现在理论是进不来的
                    return Boolean.TRUE;
                    //判断o 是 Collection 还是 字符串
//                    if(o1 instanceof Collection){
//                        List<String> list = new ArrayList<>();
//                        try {
//                            list.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
//                        } catch (Exception e) {
//
//                        }
//                        list.addAll((List) o1);
//                        return CollUtil.contains(list,o);
//                    }
//                    else{
//                        return ObjectUtil.equals(o,o1);
//                    }
                }
            }
            else{
                return Boolean.FALSE;
            }
        }
        else{
            return Boolean.FALSE;
        }



    }

    public Boolean isSubNotBelong(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){


        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }
        //判空
        if(jnpfKey.equals(jnpfValueKey)){
            //
            if(JnpfKeyConsts.COMSELECT.equals(jnpfKey) || JnpfKeyConsts.DEPSELECT.equals(jnpfKey) || JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey) || JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)){
                //
                if(o instanceof Collection){
                    //
                    Set<String> set= new HashSet<>();

                    List<String> list = new ArrayList<>();
                    List o1List= (List) o;
                    Object o3 = o1List.get(0);
                    // 单部门,但是多级
                    if(o3 instanceof  String){
                        list.add((String) o1List.get(o1List.size()-1));
                    }
                    //多部门的情况
                    else if(o3 instanceof List){
                        List<List<String>> orgList= (List<List<String>>) o1List ;
                        for (int i = 0; i < orgList.size(); i++) {
                            List<String> list1 = orgList.get(i);
                            list.add(list1.get(list1.size()-1));
                        }
                    }

                    //到此为止, 拿到了o1 的所有的 机构id
                    for (String id : list) {
                        set.add(id);//添加本身
                        List<String> underOrganizations = organizeService.getUnderOrganizations(id, true);
                        set.addAll(underOrganizations);
                    }


                    //判断o 是 Collection 还是 字符串
                    if(o1 instanceof Collection){
                        Set<String> finalSet= new HashSet<>();
                        //
                        List oList= (List) o1;
                        Object o4 = oList.get(0);
                        // 单部门,但是多级
                        if(o4 instanceof  String){
                            finalSet.add((String) oList.get(oList.size()-1));
                        }
                        //多部门的情况
                        else if(o4 instanceof List){
                            List<List<String>> orgList= (List<List<String>>) oList ;
                            for (int i = 0; i < orgList.size(); i++) {
                                List<String> list1 = orgList.get(i);
                                finalSet.add(list1.get(list1.size()-1));
                            }
                        }
                        //
                        return !set.containsAll(finalSet);

                    }
                    else{
                        return !CollUtil.contains(set,o1);
                    }
                }
                else{
                    //按现在理论是进不来的
                    return Boolean.TRUE;
                    //判断o 是 Collection 还是 字符串
//                    if(o1 instanceof Collection){
//                        List<String> list = new ArrayList<>();
//                        try {
//                            list.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
//                        } catch (Exception e) {
//
//                        }
//                        list.addAll((List) o1);
//                        return CollUtil.contains(list,o);
//                    }
//                    else{
//                        return ObjectUtil.equals(o,o1);
//                    }
                }
            }
            else{
                return Boolean.FALSE;
            }
        }
        else{
            return Boolean.FALSE;
        }




    }

    private Long queryCount(List<String> objects, List<String> types, List<String> userIds) {
        UserRelationService userRelationService = SpringContextHolder.getBean(UserRelationService.class);
        QueryWrapper<UserRelationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .in(UserRelationEntity::getObjectType, types)
                .in(UserRelationEntity::getUserId, userIds);
        if (CollectionUtil.isNotEmpty(objects)) {
            queryWrapper.lambda().in(UserRelationEntity::getObjectId, objects);
        }
        return userRelationService.count(queryWrapper);
    }

    private List<String> getUserList(Object o, String jnpfKey) {
        List<String> userIdsList = new ArrayList<>();
        // 多选  开启多选
        if (o instanceof Collection) {
            if (JnpfKeyConsts.CUSTOMUSERSELECT.equals(jnpfKey)) {
                for (String s : (List<String>) o) {
                    userIdsList.add(s.split("--")[0]);
                }
            } else {
                userIdsList.addAll((List<String>) o);
            }
        } else {
            if (JnpfKeyConsts.CUSTOMUSERSELECT.equals(jnpfKey)) {
                String userId = (String) o;
                userIdsList.add(userId.split("--")[0]);
            } else {
                userIdsList.add((String) o);
            }
        }
        return userIdsList;
    }


    public Boolean belongDept(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        UserService userService = SpringContextHolder.getBean(UserService.class);
        UserRelationService userRelationService = SpringContextHolder.getBean(UserRelationService.class);
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> types=new ArrayList<>();
        types.add(PermissionConst.ORGANIZE);
        types.add(PermissionConst.DEPARTMENT);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }

        if(!JnpfKeyConsts.COMSELECT.equals(jnpfValueKey) &&!JnpfKeyConsts.DEPSELECT.equals(jnpfValueKey) &&
        !JnpfKeyConsts.CURRORGANIZE.equals(jnpfValueKey)  ){
            return false;
        }
        List<String> userIdsList = null;
        List<String> deptIdList = null;
        switch (jnpfKey) {
            case JnpfKeyConsts.USERSELECT:
            case JnpfKeyConsts.CUSTOMUSERSELECT:
                userIdsList = getUserList(o, jnpfKey);
                deptIdList = (List<String>) o1;
                if (CollectionUtil.isEmpty(deptIdList) || queryCount(deptIdList, types, userIdsList) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            case JnpfKeyConsts.CREATEUSER:
            case JnpfKeyConsts.MODIFYUSER:
                String account=o.toString().split("/")[1];
                UserEntity userByAccount = userService.getUserByAccount(account);
                if (userByAccount == null || queryCount(null, types, Lists.newArrayList(userByAccount.getId())) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            default:
                return Boolean.FALSE;
        }
    }

    public Boolean belongRole(DelegateExecution execution,
                              String jnpfKey,Integer jnpfKeyType,String filedName,
                              String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        UserService userService = SpringContextHolder.getBean(UserService.class);
        UserRelationService userRelationService = SpringContextHolder.getBean(UserRelationService.class);
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> types=new ArrayList<>();
        types.add(PermissionConst.ROLE);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }

        if(!JnpfKeyConsts.ROLESELECT.equals(jnpfValueKey) ){
            return false;
        }
        List<String> userIdsList = null;
        String roleId = null;
        switch (jnpfKey) {
            case JnpfKeyConsts.USERSELECT:
            case JnpfKeyConsts.CUSTOMUSERSELECT:
                userIdsList = getUserList(o, jnpfKey);
                roleId = (String) o1;
                if (StringUtil.isEmpty(roleId) || queryCount(Lists.newArrayList(roleId), types, userIdsList) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            case JnpfKeyConsts.CREATEUSER:
            case JnpfKeyConsts.MODIFYUSER:
                String account = o.toString().split("/")[1];
                UserEntity userByAccount = userService.getUserByAccount(account);
                if (userByAccount == null || queryCount(null, types, Lists.newArrayList(userByAccount.getId())) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            default:
                return Boolean.FALSE;
        }
    }
    public Boolean belongPos(DelegateExecution execution,
                              String jnpfKey,Integer jnpfKeyType,String filedName,
                              String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        UserService userService = SpringContextHolder.getBean(UserService.class);
        UserRelationService userRelationService = SpringContextHolder.getBean(UserRelationService.class);
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> types=new ArrayList<>();
        types.add(PermissionConst.POSITION);
        if(ObjectUtil.isEmpty(o) || ObjectUtil.isEmpty(o1)){
            return Boolean.FALSE;
        }

        if(!JnpfKeyConsts.POSSELECT.equals(jnpfValueKey) && !JnpfKeyConsts.CURRPOSITION.equals(jnpfValueKey)){
            return false;
        }
        List<String> userIdsList = null;
        String posId = null;
        switch (jnpfKey) {
            case JnpfKeyConsts.USERSELECT:
            case JnpfKeyConsts.CUSTOMUSERSELECT:
                userIdsList = getUserList(o, jnpfKey);
                posId = (String) o1;
                if (StringUtil.isEmpty(posId) || queryCount(Lists.newArrayList(posId), types, userIdsList) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            case JnpfKeyConsts.CREATEUSER:
            case JnpfKeyConsts.MODIFYUSER:
                String account = o.toString().split("/")[1];
                UserEntity userByAccount = userService.getUserByAccount(account);
                if (userByAccount == null || queryCount(null, types, Lists.newArrayList(userByAccount.getId())) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            default:
                return Boolean.FALSE;
        }
    }

    public Boolean belongGroup(DelegateExecution execution,
                             String jnpfKey,Integer jnpfKeyType,String filedName,
                             String jnpfValueKey,Integer jnpfValueType,Object jnpfValue){
        UserService userService = SpringContextHolder.getBean(UserService.class);
        UserRelationService userRelationService = SpringContextHolder.getBean(UserRelationService.class);
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> types=new ArrayList<>();
        types.add(PermissionConst.GROUP);
        if (ObjectUtil.isEmpty(o)) {
            return Boolean.FALSE;
        }

        if(!JnpfKeyConsts.GROUPSELECT.equals(jnpfValueKey) ){
            return false;
        }
        List<String> userIdsList = null;
        String groupId = null;
        switch (jnpfKey) {
            case JnpfKeyConsts.USERSELECT:
            case JnpfKeyConsts.CUSTOMUSERSELECT:
                userIdsList = getUserList(o, jnpfKey);
                groupId = (String) o1;
                if (StringUtil.isEmpty(groupId) || queryCount(Lists.newArrayList(groupId), types, userIdsList) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            case JnpfKeyConsts.CREATEUSER:
            case JnpfKeyConsts.MODIFYUSER:
                String account = o.toString().split("/")[1];
                UserEntity userByAccount = userService.getUserByAccount(account);
                if (userByAccount == null || queryCount(null, types, Lists.newArrayList(userByAccount.getId())) == 0) {
                    return Boolean.FALSE;
                }
                return Boolean.TRUE;
            default:
                return Boolean.FALSE;
        }
    }

    private Date getValueDate(DelegateExecution execution, String jnpfValueKey, Integer jnpfValueType, Object jnpfValue, String valueFormat, Date valueDate) {
        switch (jnpfValueKey){
            case JnpfKeyConsts.DATE:
                Long o = (Long) evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
                valueDate = new Date(o);
                break;
            case JnpfKeyConsts.TIME:
                String o1 = (String) evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
                valueDate =DateUtil.parse(o1, valueFormat);
                break;
            case JnpfKeyConsts.CREATETIME:
                String o2 = (String) evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
                valueDate =DateUtil.parse(o2,TIME_FORMAT);
                break;
            case JnpfKeyConsts.MODIFYTIME:
                String o3 = (String) evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
                valueDate =DateUtil.parse(o3,TIME_FORMAT);
                break;
        }
        return valueDate;
    }

    private Date getKeyDate(DelegateExecution execution, String jnpfKey, Integer jnpfKeyType, String filedName, String valueFormat, Date keyDate) {
        switch (jnpfKey){
            case JnpfKeyConsts.DATE:
                Long o = (Long) evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
                keyDate = new Date(o);
                break;
            case JnpfKeyConsts.TIME:
                String o1 = (String) evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
                keyDate =DateUtil.parse(o1, valueFormat);
                break;
            case JnpfKeyConsts.CREATETIME:
                String o2 = (String) evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
                keyDate =DateUtil.parse(o2,TIME_FORMAT);
                break;
            case JnpfKeyConsts.MODIFYTIME:
                String o3 = (String) evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
                keyDate =DateUtil.parse(o3,TIME_FORMAT);
                break;
        }
        return keyDate;
    }

    public Boolean isAfter(DelegateExecution execution,
                            String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                            String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat){
        Date keyDate= null;
        Date valueDate = null;
        keyDate = getKeyDate(execution, jnpfKey, jnpfKeyType, filedName, nameFormat, keyDate);
        valueDate = getValueDate(execution, jnpfValueKey, jnpfValueType, jnpfValue, valueFormat, valueDate);
        if(keyDate==null || valueDate==null){
            return Boolean.FALSE;
        }
        return keyDate.after(valueDate);
    }

    public Boolean isBeforeAndEquals(DelegateExecution execution,
                           String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                           String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat){
        Date keyDate= null;
        Date valueDate = null;
        keyDate = getKeyDate(execution, jnpfKey, jnpfKeyType, filedName, nameFormat, keyDate);
        valueDate = getValueDate(execution, jnpfValueKey, jnpfValueType, jnpfValue, valueFormat, valueDate);
        if(keyDate==null || valueDate==null){
            return Boolean.FALSE;
        }
        LocalDateTime of = LocalDateTimeUtil.of(keyDate);
        LocalDateTime of1 = LocalDateTimeUtil.of(valueDate);
        return of.isBefore(of1) &&  of.isEqual(of1);
    }

    public Boolean isAfterAndEquals(DelegateExecution execution,
                                     String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                                     String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat){
        Date keyDate= null;
        Date valueDate = null;
        keyDate = getKeyDate(execution, jnpfKey, jnpfKeyType, filedName, nameFormat, keyDate);
        valueDate = getValueDate(execution, jnpfValueKey, jnpfValueType, jnpfValue, valueFormat, valueDate);
        if(keyDate==null || valueDate==null){
            return Boolean.FALSE;
        }
        LocalDateTime of = LocalDateTimeUtil.of(keyDate);
        LocalDateTime of1 = LocalDateTimeUtil.of(valueDate);
        return of.isAfter(of1) && of.isEqual(of1);
    }

    public Boolean isTimeScope(DelegateExecution execution,
                                    String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                                    String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat,
                                    String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1,String valueFormat1){
        Date keyDate= null;
        Date valueDate = null;
        Date valueDate1=null;
        keyDate = getKeyDate(execution, jnpfKey, jnpfKeyType, filedName, nameFormat, keyDate);
        valueDate = getValueDate(execution, jnpfValueKey, jnpfValueType, jnpfValue, valueFormat, valueDate);
        valueDate1 = getValueDate(execution, jnpfValueKey1, jnpfValueType1, jnpfValue1, valueFormat1, valueDate1);
        if(keyDate==null || valueDate==null ||valueDate1==null){
            return Boolean.FALSE;
        }
        return keyDate.after(valueDate) && keyDate.before(valueDate1);
    }
    public Boolean isNotTimeScope(DelegateExecution execution,
                               String jnpfKey,Integer jnpfKeyType,String filedName,String nameFormat,
                               String jnpfValueKey,Integer jnpfValueType,Object jnpfValue,String valueFormat,
                               String jnpfValueKey1,Integer jnpfValueType1,Object jnpfValue1,String valueFormat1){

        return !isTimeScope(execution,jnpfKey,jnpfKeyType,filedName,nameFormat,jnpfValueKey,jnpfValueType,jnpfValue,valueFormat,jnpfValueKey1,jnpfValueType1,jnpfValue1,valueFormat1);
    }

    public Boolean isBlong(DelegateExecution execution,
                                  String jnpfKey,Integer jnpfKeyType,String filedName,
                                  String jnpfValueKey,Integer jnpfValueType,Object jnpfValue
                                  ){

        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        List<String> list = new ArrayList<>();
        try {
            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
        } catch (Exception e) {
        }
        if (o instanceof List) {
            list.addAll((List) o);
        } else {
            list.addAll(Arrays.asList(String.valueOf(o).split(",")));
        }
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> valueList = new ArrayList<>();
        try {
            valueList.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
        } catch (Exception e) {

        }
        if (o1 instanceof List) {
            valueList.addAll((List) o1);
        } else {
            valueList.addAll(Arrays.asList(String.valueOf(o1).split(",")));
        }
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        if(CollUtil.isEmpty(valueList)){
            return Boolean.FALSE;
        }
        List<String> orgnaizeValueList=new ArrayList<>();
        orgnaizeValueList.addAll(valueList);
        LambdaQueryWrapper<OrganizeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(OrganizeEntity::getParentId,valueList);
        List<OrganizeEntity> organizeEntityList = organizeService.list(lambdaQueryWrapper);
        for (OrganizeEntity organizeEntity : organizeEntityList) {
            orgnaizeValueList.add(organizeEntity.getId());
        }

        Collection<String> intersection = CollUtil.intersection(list, orgnaizeValueList);
        if(CollUtil.isEmpty(intersection)){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    public Boolean isSubBlong(DelegateExecution execution,
                           String jnpfKey,Integer jnpfKeyType,String filedName,
                           String jnpfValueKey,Integer jnpfValueType,Object jnpfValue
    ){

        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        List<String> list = new ArrayList<>();
        try {
            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
        } catch (Exception e) {
        }
        if (o instanceof List) {
            list.addAll((List) o);
        } else {
            list.addAll(Arrays.asList(String.valueOf(o).split(",")));
        }
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> valueList = new ArrayList<>();
        try {
            valueList.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
        } catch (Exception e) {

        }
        if (o1 instanceof List) {
            valueList.addAll((List) o1);
        } else {
            valueList.addAll(Arrays.asList(String.valueOf(o1).split(",")));
        }
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        if(CollUtil.isEmpty(valueList)){
            return Boolean.FALSE;
        }
        List<String> orgnaizeValueList=new ArrayList<>();
        for (String s : valueList) {
            List<String> underOrganizations = organizeService.getUnderOrganizations(s, false);
            orgnaizeValueList.addAll(underOrganizations);
        }


        Collection<String> intersection = CollUtil.intersection(list, orgnaizeValueList);
        if(CollUtil.isEmpty(intersection)){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }



    public Boolean isNotBlong(DelegateExecution execution,
                           String jnpfKey,Integer jnpfKeyType,String filedName,
                           String jnpfValueKey,Integer jnpfValueType,Object jnpfValue
    ){

        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        List<String> list = new ArrayList<>();
        try {
            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
        } catch (Exception e) {
        }
        if (o instanceof List) {
            list.addAll((List) o);
        } else {
            list.addAll(Arrays.asList(String.valueOf(o).split(",")));
        }
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> valueList = new ArrayList<>();
        try {
            valueList.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
        } catch (Exception e) {

        }
        if (o1 instanceof List) {
            valueList.addAll((List) o1);
        } else {
            valueList.addAll(Arrays.asList(String.valueOf(o1).split(",")));
        }
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        if(CollUtil.isEmpty(valueList)){
            return Boolean.TRUE;
        }
        List<String> orgnaizeValueList=new ArrayList<>();
        orgnaizeValueList.addAll(valueList);
        LambdaQueryWrapper<OrganizeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(OrganizeEntity::getParentId,valueList);
        List<OrganizeEntity> organizeEntityList = organizeService.list(lambdaQueryWrapper);
        for (OrganizeEntity organizeEntity : organizeEntityList) {
            orgnaizeValueList.add(organizeEntity.getId());
        }

        Collection<String> intersection = CollUtil.intersection(list, orgnaizeValueList);
        if(CollUtil.isEmpty(intersection)){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    public Boolean isSubNotBlong(DelegateExecution execution,
                              String jnpfKey,Integer jnpfKeyType,String filedName,
                              String jnpfValueKey,Integer jnpfValueType,Object jnpfValue
    ){

        Object o = evaluateFiledNameValue(execution, jnpfKey, jnpfKeyType, filedName);
        List<String> list = new ArrayList<>();
        try {
            list.addAll(JsonUtil.getJsonToList(String.valueOf(o), String.class));
        } catch (Exception e) {
        }
        if (o instanceof List) {
            list.addAll((List) o);
        } else {
            list.addAll(Arrays.asList(String.valueOf(o).split(",")));
        }
        Object o1 = evaluateFiledValue(execution, jnpfValueKey, jnpfValueType, jnpfValue);
        List<String> valueList = new ArrayList<>();
        try {
            valueList.addAll(JsonUtil.getJsonToList(String.valueOf(o1), String.class));
        } catch (Exception e) {

        }
        if (o1 instanceof List) {
            valueList.addAll((List) o1);
        } else {
            valueList.addAll(Arrays.asList(String.valueOf(o1).split(",")));
        }
        OrganizeService organizeService = SpringContextHolder.getBean(OrganizeService.class);
        if(CollUtil.isEmpty(valueList)){
            return Boolean.TRUE;
        }
        List<String> orgnaizeValueList=new ArrayList<>();
        for (String s : valueList) {
            List<String> underOrganizations = organizeService.getUnderOrganizations(s, false);
            orgnaizeValueList.addAll(underOrganizations);
        }


        Collection<String> intersection = CollUtil.intersection(list, orgnaizeValueList);
        if(CollUtil.isEmpty(intersection)){
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }


    private double toDouble(Object val){
        return NumberUtil.parseNumber(val.toString()).doubleValue();
    }


    public static void main(String[] args) {
        String dateStr="00:00:06";
        String dateForamt="yyyy-MM-dd HH:mm:ss";
        DateTime parse = DateUtil.parse(dateStr, dateForamt);
        System.err.println(parse);
    }
}

